%{'SPD','CDU','CSU','Green','FDP','PDS'}
xChapel98   =[4 5.867 7.120 3  6.067 1.267];
sel98=not(isnan(xChapel98));

%{'SPD','CDU','CSU','Green','FDP','LP','Rep','SP'}
xChapel02   =[4  5.930  7.360 3.360 6.070 1.64 NaN NaN];
sel02=not(isnan(xChapel02));

%{'SPD','CDU','FDP','LP','Green','CSU','NPD'}
xChapel05   =[3.55 6.360 6.640  1.27    3.090 7.640 NaN];
sel05=not(isnan(xChapel05));

%{'CDU','SPD','FDP','LP','Green','CSU'}
xChapel09   =[6.125     3.625     6.6        1.313    3.625     7.067];
sel09=not(isnan(xChapel09));

%{'CDU','SPD','LP','Green','CSU','FDP','AFD','Pirates'}
xChapel13=[5.923 3.769 1.231 3.615 7.231 6.538   8.923 3.25];                                  
sel13=not(isnan(xChapel13));

%{'CDU','SPD','AFD','FDP','LP','Green','CSU'}
xChapel17=[5.562 3.875 9.187 6.562 1.437 2.937  7.375];
sel17=not(isnan(xChapel17));


D=GERN.M98;
sel=not(isnan(sum(D(:,sel98),2)));
D98=D(sel,sel98);
ChapelTests.P98=sum(sel98);
ChapelTests.N98=sum(sel);


D=GERN.Ma02;
sel=not(isnan(sum(D(:,sel02),2)));
D02=D(sel,sel02);
ChapelTests.P02=sum(sel02);
ChapelTests.N02=sum(sel);


D=GERN.M05;
sel=not(isnan(sum(D(:,sel05),2)));
D05=D(sel,sel05);
ChapelTests.P05=sum(sel05);
ChapelTests.N05=sum(sel);

D=GERN.M09;
sel=not(isnan(sum(D(:,sel09),2)));
D09=D(sel,sel09);
ChapelTests.P09=sum(sel09);
ChapelTests.N09=sum(sel);

D=GERN.M13;
sel=not(isnan(sum(D(:,sel13),2)));
D13=D(sel,sel13);
ChapelTests.P13=sum(sel13);
ChapelTests.N13=sum(sel);

D=GERN.M17;
sel=not(isnan(sum(D(:,sel17),2)));
D17=D(sel,sel17);
ChapelTests.P17=sum(sel17);
ChapelTests.N17=sum(sel);

filedir=pwd;

sdir=strcat(filedir,'/TESTRESULTS/');
cdir=strcat(filedir,'/TwoStepMatlab/');
addpath(cdir)

for version=1:3
    if version == 2
        warning('off','MATLAB:nearlySingularMatrix')
    else
        warning('on','MATLAB:nearlySingularMatrix')
    end
    [WM,order]=CMoment(D98,xChapel98(sel98));
    [ChapelTests.rej98,ChapelTests.s98,ChapelTests.crVa98,ChapelTests.muNu98] = ModTestTwoStep(-WM,0.05,version,10000);

    [WM,order]=CMoment(D02,xChapel02(sel02));
    [ChapelTests.rej02,ChapelTests.s02,ChapelTests.crVa02,ChapelTests.muNu02] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D05,xChapel05(sel05));
    [ChapelTests.rej05,ChapelTests.s05,ChapelTests.crVa05,ChapelTests.muNu05] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D09,xChapel09(sel09));
    [ChapelTests.rej09,ChapelTests.s09,ChapelTests.crVa09,ChapelTests.muNu09] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D13,xChapel13(sel13));
    [ChapelTests.rej13,ChapelTests.s13,ChapelTests.crVa13,ChapelTests.muNu13] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D17,xChapel17(sel17));
    [ChapelTests.rej17,ChapelTests.s17,ChapelTests.crVa17,ChapelTests.muNu17] = ModTestTwoStep(-WM,0.05,version,10000);
    
    file=strcat('ChapelTests',int2str(version));
    file=strcat(sdir,file);
    save(file,'ChapelTests')
end